<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<div class="panel_container">
    <div class="panel">
        <form id="formId" method="post" action="${ctx}/system/saveSystemDictionary">
            <input type="hidden" name="id"/>
            <div class="panel_header">
                <div><h2>系统变量维护</h2></div>
            </div>
            <div class="panel_body">
                <div>
                    <div>
                        <div class="info_item"><span>变量类型代码:</span><b>*</b>
                            <tags:select name="codeTypeId" id="codeTypeId"
                                         tableName="T_SYSTEM_DICT_TYPE" whereClause=""/></div>
                    </div>

                    <div>
                        <div class="info_item"><span>变量值代码:</span><b>*</b><input type="text" name="codeValue" id="codeValue"></div>
                        <div class="info_item"><span>变量值描述:</span><b>*</b><input type="text" name="codeDesc" id="codeDesc"></div>
                    </div>
                </div>
            </div>
            <div class="panel_footer">
                <div>
                    <input type="submit" value="保存" class="btn_blue" id="btn_save"/>
                    <input type="button" value="返回" class="btn_blue" id="btn_back"/>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    function loadEntity(){
        var _id = "${id}";
        if(_id!="" && _id!="null"){
            $.ajax({
                url:"${ctx}/system/getSystemDictionary",
                data: {"id": _id},
                success: function (data) {
                    $("#formId").autoMatch(data);
                }
            })
        }
    }

    function gotoDetailListPage(){
        linkTo("${ctx}/system/systemVariable");
    }

    $(function () {
        $("#btn_back").bind("click",gotoDetailListPage);

        $("#formId").validate({
            rules:{
                codeTypeId: "required",
                codeValue: "required",
                codeDesc: "required"
            },
            messages:{
                codeTypeId: "变量类型代码必填",
                codeValue: "变量值代码必填",
                codeDesc: "变量值描述必填"
            },
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    success: function(response) {
                        $.prompt("保存成功");
                        window.setTimeout(function(){
                            gotoDetailListPage();
                        },2000);
                    },

                    error: function(response){
                        $.prompt("保存失败:"+response,"错误");
                    }
                });
            }
        });
        loadEntity();
    });

</script>

